<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //利用构造函数创建对象
        //构造函数：就是把我们对象里面一些相同的属性和方法抽离出来封装到函数里面
        //语法格式
        // function 构造函数名() {
        //     this.属性 = 值;
        //     this.方法 = function () { }
        // }
        // new 构造函数名();


        function Star(uname, age, sex) {
            //构造函数首字母要大写Star
            this.name = uname;
            this.age = age;
            this.sex = sex;
            this.sing = function (song) {
                console.log(song);
            }
        }
        var sjy = new Star('孙金瑶', 18, '女');
        //不需要return就可以返回
        console.log(sjy.name);
        console.log(sjy['sex']);
        sjy.sing('冰雨');
        //多个对象
        var ldh = new Star('刘德华', 19, '男');
        console.log(ldh.name);
        console.log(ldh['sex']);
        ldh.sing('小苹果');
    </script>
</head>

<body>

</body>

</html>